#pragma once

#include<iostream>
#include<string>
#include<vector>
#include<fstream>
#include<boost/algorithm/string.hpp>
#include"cppjieba/Jieba.hpp"
#include"log.hpp"

namespace util
{
    class FindUtil
    {
        public:
            static bool ReadFile(const std::string& file_path, std::string* file_content)
            {
                std::ifstream in(file_path, std::ios::in);
                if(!in.is_open())
                {
                    LOG(ERROR, "open " + file_path + "failed");
                    return false;
                }

                std::string line;
                while(std::getline(in, line))
                {
                    *file_content += line;
                }
                
                in.close();
                return true;
            }
    };

    class StringUtil
    {
        public:
            static void Split(const std::string& src, std::vector<std::string>* dst, const std::string& sep)
            {
                //boost split 非常方便
                boost::split(*dst, src, boost::is_any_of(sep), boost::token_compress_on);
            }
    };

    // ln -s ./../cppjieba/include/cppjieba cppjiaba
    // ln -s ./../cppjieba/dict/ dict
    //想删除用 unlink xxx
    //参考 test/demo.cpp
    const char* const DICT_PATH = "./dict/jieba.dict.utf8";
    const char* const HMM_PATH = "./dict/hmm_model.utf8";
    const char* const USER_DICT_PATH = "./dict/user.dict.utf8";
    const char* const IDF_PATH = "./dict/idf.utf8";
    const char* const STOP_WORD_PATH = "./dict/stop_words.utf8";

    class JiebaUtil
    {
        private:
            static cppjieba::Jieba jieba;
        public:
            static void CutString(const std::string& src, std::vector<std::string>* words)
            {
                jieba.CutForSearch(src, *words);
            }
    };

    cppjieba::Jieba JiebaUtil::jieba(DICT_PATH,
                HMM_PATH,
                USER_DICT_PATH,
                IDF_PATH,
                STOP_WORD_PATH);
}

